//
//  ZbHeadView.m
//  喜马拉雅FM
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 lanou.com. All rights reserved.
//

#define WIDTH [UIScreen mainScreen].bounds.size.width

#import "ZbHeadView.h"
#import "UIImageView+WebCache.h"

@interface ZbHeadView ()

@property (nonatomic, retain) UILabel *labelForTitle;
@property (nonatomic, retain) UIImageView *pictureLarge;
@property (nonatomic, retain) UIImageView *pictureSmall;
@property (nonatomic, retain) UILabel *labelForSubTitle;
@property (nonatomic, retain) UILabel *labelForContent;

@property (nonatomic, retain) UIViewController *secendVc;

@property (nonatomic, retain) UIView *visualView;
@property (nonatomic, retain) UIImageView *imageBackGround;

@end

@implementation ZbHeadView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {

        [self createSubViews];
    }
    return self;
}

- (void)createSubViews {
    
    self.imageBackGround = [[UIImageView alloc]init];
    self.imageBackGround.frame = self.bounds;
    self.imageBackGround.userInteractionEnabled = YES;
    [self addSubview:self.imageBackGround];
    [self.imageBackGround release];
    
    // 毛玻璃视图层.
    UIBlurEffect *blur = [UIBlurEffect effectWithStyle:2];
    self.visualView = [[UIVisualEffectView alloc]initWithEffect:blur];
    self.visualView.frame = self.bounds;
    [self.imageBackGround addSubview:self.visualView];
    [self.visualView release];

    self.labelForTitle = [[UILabel alloc]initWithFrame:CGRectMake(50, 20, [UIScreen mainScreen].bounds.size.width - 100, 30)];
    self.labelForTitle.text = @"我们办人事大讲堂";
    self.labelForTitle.textAlignment = NSTextAlignmentCenter;
    self.labelForTitle.textColor = [UIColor whiteColor];
    self.labelForTitle.font = [UIFont systemFontOfSize:20];
    [self addSubview:self.labelForTitle];
    [self.labelForTitle release];
    
    UIButton *buttonLeft = [UIButton buttonWithType:UIButtonTypeCustom];
    buttonLeft.frame = CGRectMake(10, 20, 30 , 30);
    [buttonLeft setBackgroundImage:[UIImage imageNamed:@"iconfont-jiantouzuo-2"] forState:UIControlStateNormal];
    [self addSubview:buttonLeft];
    [buttonLeft addTarget:self action:@selector(handleAction:) forControlEvents:UIControlEventTouchUpInside];
    
//    UIButton *buttonRight = [UIButton buttonWithType:UIButtonTypeCustom];
//    buttonRight.frame = CGRectMake([UIScreen mainScreen].bounds.size.width - 30, 20, 30, 30);
//    [buttonRight setBackgroundImage:[UIImage imageNamed:@"iconfont-sangedian"] forState:UIControlStateNormal];
//    [self addSubview:buttonRight];
//    [buttonRight addTarget:self action:@selector(handleAlertView:) forControlEvents:UIControlEventTouchUpInside];
    
    
    self.pictureLarge = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1.jpg"]];
    self.pictureLarge.frame = CGRectMake(10, 60, 100, 100);
    [self addSubview:self.pictureLarge];
    [self.pictureLarge release];
    
    self.pictureSmall = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1.jpg"]];
    self.pictureSmall.frame = CGRectMake(120, 70, 30, 30);
    self.pictureSmall.layer.cornerRadius = 15;
    self.pictureSmall.layer.masksToBounds = YES;
    [self addSubview:self.pictureSmall];
    [self.pictureSmall release];
    
    self.labelForSubTitle = [[UILabel alloc]initWithFrame:CGRectMake(160, 70, 150, 30)];
    self.labelForSubTitle.text = @"我们办人事";
    self.labelForSubTitle.textColor = [UIColor whiteColor];
    self.labelForSubTitle.font = [UIFont systemFontOfSize:18];
    [self addSubview:self.labelForSubTitle];
    [self.labelForSubTitle release];
    
    self.labelForContent = [[UILabel alloc]initWithFrame:CGRectMake(120, 100, WIDTH - 120 - 50, 60)];
    self.labelForContent.text = @"我们办人事是一个泛娱乐化的职业";
    self.labelForContent.numberOfLines = 0;
    self.labelForContent.textColor = [UIColor lightGrayColor];
    self.labelForContent.font = [UIFont systemFontOfSize:17];
    [self addSubview:self.labelForContent];
    [self.labelForContent release];
}


- (void)passDataWith:(NSDictionary *)dic {
 
    self.labelForTitle.text = [dic objectForKey:@"title"];
    NSString *str = [dic objectForKey:@"coverLarge"];
    [self.pictureLarge sd_setImageWithURL:[NSURL URLWithString:str]];
    
    str = [dic objectForKey:@"coverSmall"];
    [self.pictureSmall sd_setImageWithURL:[NSURL URLWithString:str]];
    [self.imageBackGround sd_setImageWithURL:[NSURL URLWithString:str]];
    
    str = [dic objectForKey:@"nickname"];
    self.labelForSubTitle.text = str;
    
    str = [dic objectForKey:@"intro"];
    self.labelForContent.text = str;

}


- (void)handleAction:(UIButton *)button {

    id object = [self nextResponder];
    while (![object isKindOfClass:[UIViewController class]] &&
           object != nil) {
        object = [object nextResponder];
    }
    self.secendVc = (UIViewController*)object;
    [self.secendVc.navigationController popViewControllerAnimated:YES];
    
    [self.secendVc.navigationController setNavigationBarHidden:NO animated:YES];

}

- (void)handleAlertView:(UIButton *)button {

    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction *actionShare = [UIAlertAction actionWithTitle:@"分享" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    UIAlertAction *actionReport = [UIAlertAction actionWithTitle:@"举报" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//        [alert dismissViewControllerAnimated:YES completion:nil];
    }];
    
    [alert addAction:actionShare];
    [alert addAction:actionReport];
    [alert addAction:actionCancel];
    
    id object = [self nextResponder];
    while (![object isKindOfClass:[UIViewController class]] &&
           object != nil) {
        object = [object nextResponder];
    }
    self.secendVc = (UIViewController*)object;

    
    [self.secendVc presentViewController:alert animated:YES completion:nil];
    
}

@end
